package com.yonyou.pmclouds.contacttype.process;

import java.util.List;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.exception.BuziExCodeConst;
import com.yonyou.pmclouds.contacttype.entity.ContactTypeVO;
import com.yonyou.pmclouds.contacttype.mapper.ContactTypeMapper;

public class ContypeUniqueCheck implements SingleProcessor<ContactTypeVO> {

	private ContactTypeMapper mapper;

    public ContypeUniqueCheck(ContactTypeMapper mapper) {
        this.mapper = mapper;
    }
	
	@Override
	public void process(ContactTypeVO vo, ContactTypeVO orig) throws BusinessException {
		List<ContactTypeVO> repeatList = checkRepeat(vo);
        if (repeatList != null && repeatList.size() > 0)
            throw new BusinessException("名称重复，保存失败！", BuziExCodeConst.CODE_NAME_DUPLICATE);
	}
	
	private List<ContactTypeVO> checkRepeat(ContactTypeVO contactTypeVO) {
        return mapper.checkRepeat(contactTypeVO);
    }

}
